home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-wos-src / vlink / errors.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  8KB  |  207 lines

  1. /* $VER: vlink errors.c V0.6a (19.12.98)
  2.  *
  3.  * This file is part of vlink, a portable linker for multiple
  4.  * object formats.
  5.  * Copyright (c) 1997-99  Frank Wille
  6.  *
  7.  * vlink is freeware and part of the portable and retargetable ANSI C
  8.  * compiler vbcc, copyright (c) 1995-99 by Volker Barthelmann.
  9.  * vlink may be freely redistributed as long as no modifications are
  10.  * made and nothing is charged for it. Non-commercial usage is allowed
  11.  * without any restrictions.
  12.  * EVERY PRODUCT OR PROGRAM DERIVED DIRECTLY FROM MY SOURCE MAY NOT BE
  13.  * SOLD COMMERCIALLY WITHOUT PERMISSION FROM THE AUTHOR.
  14.  *
  15.  *
  16.  * v0.6a (19.12.98) phx
  17.  *       Error 61, when objects have different endianess.
  18.  * v0.6  (23.10.98) phx
  19.  *       Shared objects (60).
  20.  * v0.5e (05.10.98) phx
  21.  *       Error 59.
  22.  * v0.5a (28.06.98) phx
  23.  *       Multiple symbol definition (error 19) was turned into a warning.
  24.  * v0.4  (05.06.98) phx
  25.  *       Warnings for section-merging.
  26.  * v0.3  (15.04.98) phx
  27.  *       Changed all "%s(%s+0x%x):" strings into "%s (%s+0x%x):"
  28.  *       New error messages for ELF and AR support.
  29.  * v0.1  (27.02.98) phx
  30.  *       First version that seems to link AmigaOS ADOS and EHF
  31.  *       objects and libraries. Many common features, like linking
  32.  *       sections together which have relative references, are
  33.  *       still missing. Also, PowerPC-ELF32 support is about to come.
  34.  * v0.0  (04.08.97) phx
  35.  *       File created. Project started on a beautiful summer-day
  36.  *       at the North Sea beach of Cuxhaven. :)
  37.  *       Based on errors.c v0.4 of the portable PowerPC assembler "pasm".
  38.  */
  39.  
  40.  
  41. #define ERRORS_C
  42. #include "vlink.h"
  43.  
  44.  
  45. /* error flags */
  46. #define EF_NONE 0
  47. #define EF_WARNING 1
  48. #define EF_ERROR 2
  49. #define EF_FATAL 3
  50.  
  51.  
  52. void error(int,...);
  53. void ierror(char *,...);
  54.  
  55.  
  56.  
  57. static struct {
  58.   char *txt;
  59.   int flags;
  60. } errors[] = {
  61.   /* startup, command line */
  62.   "",EF_NONE,
  63.   "Out of memory",EF_FATAL,                                         /* 01 */
  64.   "Unrecognized option '%s'",EF_WARNING,
  65.   "Unknown link mode: %s",EF_WARNING,
  66.   "Unknown argument for option -d: %c",EF_WARNING,
  67.   "Option '-%c' requires an argument",EF_FATAL,                     /* 05 */
  68.   "No input files",EF_FATAL,
  69.   "File \"%s\" has a read error",EF_FATAL,
  70.   "Cannot open \"%s\": No such file or directory",EF_FATAL,
  71.   "Invalid target format \"%s\"",EF_FATAL,
  72.   "Directory \"%s\" could not be examined",EF_ERROR,                /* 10 */
  73.   "%s: File format not recognized",EF_FATAL,
  74.   "\"%s\" is already an executable file",EF_WARNING,
  75.   "%s: File format corrupted",EF_FATAL,
  76.   "Can't open \"%s\" for output",EF_WARNING,
  77.   "%s: Unexpected end of section %s in %s",EF_FATAL,                /* 15 */
  78.   "%s: %s appeared twice in %s",EF_FATAL,
  79.   "%s: Misplaced %s in %s",EF_FATAL,
  80.   "%s: Symbol definition %s in %s uses unsupported type %d",EF_FATAL,
  81.   "%s: Global symbol %s (%s) is already defined in %s (%s)",EF_WARNING,
  82.   "%s: Unresolved reference to symbol %s in %s uses "               /* 20 */
  83.     "unsupported type %d",EF_FATAL,
  84.   "%s (%s+0x%x): Undefined reference to %s",EF_ERROR,
  85.   "Protection of section %s was changed from %s to %s",EF_WARNING,
  86.   "Alignment of section %s was changed from %d to %d",EF_WARNING,
  87.   "%s (%s+0x%x): Illegal relative reference to %s+0x%x",EF_ERROR,    /* 24 */
  88.   "%s (%s+0x%x): %dbit relative reference to %s+0x%x out of range",EF_ERROR,
  89.   "%s (%s+0x%x): Referenced absolute symbol %s=0x%x + 0x%x "
  90.     "doesn't fit into %d bits",EF_ERROR,
  91.   "%s (%s+0x%x): Illegal relative reference to symbol %s",EF_ERROR,
  92.   "%s (%s+0x%x): Relative reference to relocatable symbol %s=0x%x + 0x%x "
  93.     "doesn't fit into %d bits",EF_ERROR,
  94.   "Can't create output file %s",EF_ERROR,
  95.   "Target file format doesn't support shared objects",EF_ERROR,     /* 30 */
  96.   "Error while writing to %s",EF_FATAL,
  97.   "Target %s: Unsupported relocation type %s at %s+0x%x",EF_ERROR,
  98.   "Target %s: Can't reproduce symbol %s, which is a %s%s%s",EF_ERROR,
  99.   "Option '%s' requires an argument",EF_FATAL,
  100.   "-baseoff offsets are valid from 0 to 0x8000",EF_WARNING,         /* 35 */
  101.   "%s (%s+0x%x): Base relative reference to relocatable symbol "
  102.     "%s=0x%x + 0x%x doesn't fit into %d bits",EF_ERROR,
  103.   "%s: Malformatted archive member %s",EF_FATAL,
  104.   "%s: Empty archive ignored. Unable to determine file format",EF_WARNING,
  105.   "%s: %s doesn't support shared objects in library archives",EF_FATAL,
  106.   "%s: %s doesn't support executables in library archives",EF_FATAL,/* 40 */
  107.   "%s (%s): Illegal format / file corrupted",EF_FATAL,
  108.   "%s: Consistency check for archive member %s failed",EF_FATAL,
  109.   "%s: Invalid ELF section header index (%d) in %s",EF_FATAL,
  110.   "%s: ELF section header #%d has illegal offset in %s",EF_FATAL,
  111.   "%s: ELF section header string table has illegal type in %s",     /* 45 */
  112.     EF_ERROR,
  113.   "%s: ELF section header string table has illegal offset in %s",EF_ERROR,
  114.   "%s: ELF program header table in %s was ignored",EF_WARNING,
  115.   "%s: ELF section header type %d in %s is not needed in "
  116.     "relocatable objects",EF_WARNING,
  117.   "%s: Illegal section offset for %s in %s",EF_FATAL,
  118.   "%s: ELF %s table has illegal type in %s",EF_FATAL,               /* 50 */
  119.   "%s: ELF %s table has illegal offset in %s",EF_FATAL,
  120.   "%s: %s in %s defines relocations relative to a non-existing ELF "
  121.     "section with index=%d",EF_FATAL,
  122.   "%s: Symbol %s, defined in %s, has an invalid reference to "
  123.     "a non-existing ELF section with index=%d",EF_FATAL,
  124.   "%s: Illegal ELF symbol type %d for %s in %s",EF_ERROR,
  125.   "%s: ELF symbol %s has illegal binding type %d in %s",EF_ERROR,   /* 55 */
  126.   "%s: Symbol %s in %s is multiply defined (first occurence in %s)",EF_ERROR,
  127.   "%s: Merging a code section with name \"__MERGED\"",EF_WARNING,
  128.   "Relative references between %s section \"%s\" and %s section "
  129.     "\"%s\" (%s) force a combination of the two",EF_WARNING,
  130.   "Can't define %s as section label. Symbol already exists.",EF_ERROR,
  131.   "%s: ELF section header type %d in %s is not needed in "          /* 60 */
  132.     "shared objects",EF_WARNING,
  133.   "%s: Endianess differs from previous objects",EF_FATAL,
  134. };
  135.  
  136.  
  137. void error(int errn,...)
  138. /* prints errors and warnings */
  139. {
  140.   struct GlobalVars *gv = &gvars;
  141.   va_list vl;
  142.   char *errtype;
  143.   int flags = errors[errn].flags;
  144.  
  145.   if ((flags == EF_WARNING) && gv->dontwarn)
  146.     return;
  147.   switch(flags) {
  148.     case EF_WARNING:
  149.       errtype = "Warning";
  150.       break;
  151.     case EF_ERROR:
  152.       gv->returncode = EXIT_FAILURE;
  153.       errtype = "Error";
  154.       break;
  155.     case EF_FATAL:
  156.       gv->returncode = EXIT_FAILURE;
  157.       errtype = "Fatal error";
  158.       break;
  159.     default:
  160.       ierror("Illegal error type %d",flags);
  161.       gv->returncode = EXIT_FAILURE;
  162.       errtype = "";
  163.       break;
  164.   }
  165.  
  166.   /* print error message */
  167.   fprintf(stderr,"%s %d: ",errtype,errn);
  168.   va_start(vl,errn);
  169.   vfprintf(stderr,errors[errn].txt,vl);
  170.   va_end(vl);
  171.   fprintf(stderr,".\n");
  172.  
  173.   switch(flags) {
  174.     case EF_ERROR:
  175.       /* check if maximum number of errors reached */
  176.       if (++gv->errcnt >= gv->maxerrors) {
  177.         gv->errcnt = 0;
  178.         fprintf(stdout,"Do you want to continue (y/n) ? ");
  179.         fflush(stdin);
  180.         if (toupper((unsigned char)getchar()) == 'N')
  181.           cleanup(gv);
  182.       }
  183.       /* avoid writing of output file in error case */
  184.       gv->errflag = TRUE;
  185.       break;
  186.     case EF_FATAL:
  187.       fprintf(stderr,"Aborting.\n");  /* fatal error aborts the linker */
  188.       cleanup(gv);
  189.       break;
  190.   }
  191. }
  192.  
  193.  
  194. void ierror(char *errtxt,...)
  195. /* display internal error and quit */
  196. {
  197.   struct GlobalVars *gv = &gvars;
  198.   va_list vl;
  199.  
  200.   fprintf(stderr,"\nINTERNAL ERROR: ");
  201.   va_start(vl,errtxt);
  202.   vfprintf(stderr,errtxt,vl);
  203.   va_end(vl);
  204.   fprintf(stderr,".\nAborting.\n");
  205.   cleanup(gv);
  206. }
  207.